What is @babel/plugin-transform-async-generator-functions?
The @babel/plugin-transform-async-generator-functions package is a Babel plugin that transforms async generator functions and for-await loops to ES2015/ES6-compatible code. This allows developers to use async generator functions in environments that do not support them natively.
What are @babel/plugin-transform-async-generator-functions's main functionalities?
Transformation of async generator functions
This feature allows developers to write async generator functions, which are then transformed into code that can be executed in environments that do not support async generators natively.
async function* asyncGenerator() {
var i = 0;
while (i < 3) {
yield i++;
}
}
Transformation of for-await loops
This feature enables the use of for-await loops to iterate over async iterable objects, which is transformed into a series of promise resolutions compatible with older JavaScript engines.
async function iterateAsyncGenerator() {
for await (const num of asyncGenerator()) {
console.log(num);
}
}
Other packages similar to @babel/plugin-transform-async-generator-functions
regenerator-runtime
The regenerator-runtime package provides a runtime for Regenerator-compiled generator and async functions. It is similar to @babel/plugin-transform-async-generator-functions in that it allows the use of async functions in older environments, but it is a runtime rather than a compile-time plugin.
babel-plugin-transform-async-to-generator
This plugin transforms async functions to generator functions. While it does not directly transform async generator functions, it serves a similar purpose in allowing async functions to run in environments that do not support them natively.
@babel/plugin-transform-async-generator-functions
Turn async generator functions into ES2015 generators
See our website @babel/plugin-transform-async-generator-functions for more information.
Install
Using npm:
npm install --save-dev @babel/plugin-transform-async-generator-functions
or using yarn:
yarn add @babel/plugin-transform-async-generator-functions --dev